<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button class="btn1">存localstorage</button>
    <button class="btn2">获取localstorage</button>
    <button class="btn3">删除localstorage</button>
    <button class="btn4">删除所有的localstorage</button>
    <script>
        // cookie:离线存储 ：cookie 数据量小 ，占用网络；存小数据量 
        // 数量相对来说大些 localStorage 本地存储  5M
        // localStorage : 1.设置localstorage  2.获取localstorage 3.删除  没有时效性；
        // 1.设置
        document.querySelector(".btn1").onclick = function(){
            // localStorage.setItem("name","张三");
            // localStorage.setItem("age",18);
            let arr = [{name:"张三"},{name:"李四"}];
            // localStorage.setItem("arr",arr);
            localStorage.setItem("arr",JSON.stringify(arr));
        }

        // 获取
        document.querySelector(".btn2").onclick = function(){
          let res =   localStorage.getItem("arr");
        //   console.log(res);
        console.log(JSON.parse(res));
        }

        // 删除 指定的localstorage
        document.querySelector(".btn3").onclick = function(){
            localStorage.removeItem("name");
        }

        // 删除所有的localstorage
        document.querySelector(".btn4").onclick = function(){
            localStorage.clear();
        }

        // 通过ajax请求数据，如果数据请求到那么就通过localstorage 缓存数据，然后第二次不发送ajax了；

    </script>
</body>
</html>